<?php

namespace App\Http\Controllers\Home;


use App\Model\CategoryModel;
use App\Model\NewsModel;
use Illuminate\Support\Facades\Input;

class NewsController extends CommonController
{
    //
    public function index(){
        $navigate =  $this->navegate;
        $cate = Input::get('cate_id')?Input::get('cate_id'):0;
        $where = array();
        if($cate>0){
            $where['type'] = $cate;
        }else{
            $where['type'] = 2;
            $cate = 2;
        }
        $list = NewsModel::where($where)->paginate(25);
        $hot = NewsModel::where('type',3)->orderBy('create_time','desc')->limit(10)->get();
        $cate_title = CategoryModel::select('cate_title')->find($cate)->cate_title;
        return view('home.news.index',compact('hot','list','cate_title'))->with('navigate',$navigate);
    }

    public function newsShow()
    {
        $id = Input::get('news_id');
        $navigate =  $this->navegate;
        $hot = NewsModel::where('type',3)->orderBy('create_time','desc')->limit(10)->get();
        $data = NewsModel::find($id);
        $data->click++;
        $data->save();
        $cate_title = CategoryModel::select('cate_title')->find($data->type)->cate_title;
        return view('home.news.news',compact('hot','data','cate_title'))->with('navigate',$navigate);
    }
}
